﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Reflection;

namespace BAL
{
    public partial class Main2 : Form
    {
        private LoginService.BarcodeJudgeServices bjs = new BAL.LoginService.BarcodeJudgeServices();
        private string ID;
        public Main2()
        {
            InitializeComponent();
        }

        public Main2( string _ID)
        {
            InitializeComponent();
            this.ID = _ID;
        }

        public void SetButtonValue()
        { 
            btnAbanINStock.Enabled = false; 
            btnAbandoned.Enabled = false;
            btnICEntrust.Enabled = false;
            btnLockStoreBill.Enabled = false;
            btnInventory.Enabled = false;
            btnProductMain.Enabled = false;
        }

        public string JudgeAuthority()
        {

            string result = string.Empty;
            try
            {
                result = bjs.GetPDAAuthority(this.ID);

            }
            catch (Exception ex)
            {
                MessageBox.Show("程序出错！", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button3);

            }

            return result;

        }

        private void Main2_Load(object sender, EventArgs e)
        {
            label1.Text = Program.user;
            SetButtonValue();
            string action = JudgeAuthority();
            if (action != null && action != "")
            {
                string[] data = action.Split(',');
                for (int i = 0; i < data.Length; i++)
                {
                    if (data[i] == "AbanINStock")//红冲入库
                    {
                        btnAbanINStock.Enabled = true;
                    }
                    if (data[i] == "Abandoned")//报废
                    {
                        btnAbandoned.Enabled = true;
                    }                   
                    if (data[i] == "LockStoreBill") //拆包出库
                    {
                        btnLockStoreBill.Enabled = true;
                    }
                    if (data[i] == "Inventory")//库存盘点
                    {
                        btnInventory.Enabled = true;
                    }
                    if (data[i] == "ProductMain")
                    {
                        btnProductMain.Enabled = true;
                    }
                    
                    if (data[i] == "ICEntrust")//委外
                    {
                        btnICEntrust.Enabled = true;
                    }
                }
            }
        }


        //报废出库
        private void button1_Click(object sender, EventArgs e)
        {
            Abandoned iw = new Abandoned(this.ID);
            iw.Show();
            this.Hide();
        }
        //上一页
        private void bt_up_Click(object sender, EventArgs e)
        {
            Main iw = new Main(this.ID);
            iw.Show();
            this.Hide();
        }

        //报废入库
        private void button2_Click(object sender, EventArgs e)
        {
            AbanINStock iw = new AbanINStock(this.ID);
            iw.Show();
            this.Hide();
        }
        
        //库存盘点
        private void button4_Click(object sender, EventArgs e)
        {
            Inventory iw = new Inventory(this.ID);
            iw.Show();
            this.Hide();
        }
        //总成出库
        private void button3_Click(object sender, EventArgs e)
        {
            FastOutStock iw = new FastOutStock(this.ID);
            iw.Show();
            this.Hide();
        }

        //返回到登录页面
        private void button6_Click(object sender, EventArgs e)
        {
            Login iw = new Login();
            iw.Show();
            this.Hide();

        }
        //退出
        private void button5_Click(object sender, EventArgs e)
        {
            Application.Exit();
            //用户存储文件里
            string location = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase.ToString());
            string path = location + "\\Machines.txt";

            FileStream stream = File.Open(path, FileMode.OpenOrCreate, FileAccess.Write);
            stream.Seek(0, SeekOrigin.Begin);
            stream.SetLength(0);
            stream.Close();
        }
        //拆包出库
        private void button7_Click(object sender, EventArgs e)
        {
            LockStoreBill loc = new LockStoreBill(this.ID);
            loc.Show();
            this.Hide();

        }
        //虚采入库
        private void btnProductMain_Click(object sender, EventArgs e)
        {
            ProductMain pro = new ProductMain(this.ID);
            pro.Show();
            this.Hide();
        }

        //下一页
        private void button1_Click_2(object sender, EventArgs e)
        {
            Main3 iw = new Main3(this.ID);
            iw.Show();
            this.Hide();
        }
    }
}